// 用户角色枚举
export enum UserRole {
  ADMIN = 'admin',
  USER = 'user'
}

// 角色权限映射
export const RolePermissions = {
  [UserRole.ADMIN]: [
    'user:read',
    'user:create',
    'user:update',
    'user:delete',
    'admin:manage'
  ],
  [UserRole.USER]: [
    'user:read'
  ]
} as const

// 角色显示名称
export const RoleDisplayNames = {
  [UserRole.ADMIN]: '管理员',
  [UserRole.USER]: '普通用户'
} as const

// 用户类型
export interface IUser {
  id: number
  username: string
  email: string
  role: UserRole
  createdAt: string
  updatedAt: string
}

// API响应的用户类型（不包含密码）
export interface IUserResponse extends IUser {}

// 创建用户请求
export interface ICreateUserRequest {
  username: string
  email: string
  password: string
  role?: UserRole
}

// 更新用户请求
export interface IUpdateUserRequest {
  username?: string
  email?: string
  password?: string
  role?: UserRole
}

// 登录请求
export interface ILoginRequest {
  username: string
  password: string
}

// 注册请求
export interface IRegisterRequest {
  username: string
  email: string
  password: string
}

// 角色信息
export interface IRoleInfo {
  value: UserRole
  displayName: string
  permissions: readonly string[]
}

// API响应基础类型
export interface IApiResponse<T = any> {
  success: boolean
  message: string
  data?: T
  error?: string
}

// 认证响应
export interface IAuthResponse {
  success: boolean
  message: string
  data: {
    user: IUserResponse
    token: string
  }
}

// 用户列表响应
export interface IUsersResponse {
  success: boolean
  message: string
  data: IUserResponse[]
  total: number
}

// 角色列表响应
export interface IRolesResponse {
  success: boolean
  message: string
  data: {
    roles: IRoleInfo[]
    total: number
  }
}

// 角色统计
export interface IRoleStats {
  role: string
  displayName: string
  count: number
  permissions: string[]
}

// 角色统计响应
export interface IRoleStatsResponse {
  success: boolean
  message: string
  data: {
    statistics: IRoleStats[]
    totalUsers: number
  }
}

// 权限检查响应
export interface IPermissionCheckResponse {
  success: boolean
  message: string
  data: {
    userId: number
    username: string
    role: string
    roleDisplayName: string
    permission: string
    hasPermission: boolean
    allPermissions: string[]
  }
}
